package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.dao.FindAllDepDao;
import com.jx.daoimpl.FindAllDepDaoImpl;
import com.jx.model.Dep;
import com.jx.service.FindAdminsService;
import com.jx.service.FindSomeAdminsService;
import com.jx.servicrimpl.FindAdminsServiceImpl;
import com.jx.servicrimpl.FindSomeAdminsServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 找到所有的管理员
 * @author zzzzzzz
 *
 */
public class FindAdminsController extends HttpServlet{
	FindAdminsService fas=new FindAdminsServiceImpl();
	FindSomeAdminsService fsas=new FindSomeAdminsServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//设置字符集
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		

		//获取前台搜索框的数据
		String searchname=req.getParameter("searchname");
		//获取前台分页
		int page = Integer.parseInt(req.getParameter("page"));
		int pagesize = Integer.parseInt(req.getParameter("rows"));
		int start=(page-1)*pagesize;
		//实例化json对象
		JSONObject admins=new JSONObject();
		//判断搜索框是否有值
		if(searchname!=null){
			admins=fsas.findSomeAdminService(searchname,start,pagesize);
		}else{
			admins=fas.findAdminsService(start,pagesize);
		}
//		传呼数据
		PrintWriter pw=resp.getWriter();
		pw.write(admins.toString());
		
	}
}
